//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.SysMessage;
import com.ruoyi.system.service.ISysMessageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping({"/message"})
public class SysMessageController extends BaseController {
    @Autowired
    private ISysMessageService sysMessageService;

    public SysMessageController() {
    }

    @RequiresPermissions({"system:message:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(SysMessage sysMessage) {
        PageDomain pageDomain = new PageDomain();
        BeanUtils.copyProperties(sysMessage, pageDomain);
        this.startPage(pageDomain);
        List<SysMessage> list = this.sysMessageService.selectSysMessageList(sysMessage);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"system:message:export"})
    @Log(
            title = "站内信",
            businessType = BusinessType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, SysMessage sysMessage) {
        List<SysMessage> list = this.sysMessageService.selectSysMessageList(sysMessage);
        ExcelUtil<SysMessage> util = new ExcelUtil(SysMessage.class);
        util.exportExcel(response, list, "站内信数据");
    }

    @RequiresPermissions({"system:message:query"})
    @GetMapping({"/getInfo"})
    public AjaxResult getInfo(Long messageId) {
        return AjaxResult.success(this.sysMessageService.selectSysMessageByMessageId(messageId));
    }

    @Log(
            title = "站内信",
            businessType = BusinessType.INSERT
    )
    @PostMapping({"/add"})
    public AjaxResult add(@RequestBody SysMessage sysMessage) {
        return this.toAjax(this.sysMessageService.insertSysMessage(sysMessage));
    }

    @RequiresPermissions({"system:message:edit"})
    @Log(
            title = "站内信",
            businessType = BusinessType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody SysMessage sysMessage) {
        return this.toAjax(this.sysMessageService.updateSysMessage(sysMessage));
    }

    @RequiresPermissions({"system:message:remove"})
    @Log(
            title = "站内信",
            businessType = BusinessType.DELETE
    )
    @PostMapping({"/remove"})
    public AjaxResult remove(@RequestBody Long[] messageIds) {
        return this.toAjax(this.sysMessageService.deleteSysMessageByMessageIds(messageIds));
    }
}
